package service

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
)

//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateUserOrderGetPic
//@description: 创建UserOrderGetPic记录
//@param: userOrderGetPic model.UserOrderGetPic
//@return: err error

func CreateUserOrderGetPic(userOrderGetPic model.UserOrderGetPic) (err error) {
	err = global.GVA_DB.Create(&userOrderGetPic).Error
	return err
}


//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteUserOrderGetPic
//@description: 删除UserOrderGetPic记录
//@param: userOrderGetPic model.UserOrderGetPic
//@return: err error

func DeleteUserOrderGetPic(userOrderGetPic model.UserOrderGetPic) (err error) {
	err = global.GVA_DB.Delete(&userOrderGetPic).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteUserOrderGetPicByIds
//@description: 批量删除UserOrderGetPic记录
//@param: ids request.IdsReq
//@return: err error

func DeleteUserOrderGetPicByIds(ids request.IdsReq) (err error) {
	err = global.GVA_DB.Delete(&[]model.UserOrderGetPic{},"id in ?",ids.Ids).Error
	return err
}


func DeleteUserOrderGetPicByOrderId(OrderId int) (err error) {
	err = global.GVA_DB.Delete(&[]model.UserOrderGetPic{},"order_id = ?",OrderId).Error
	return err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateUserOrderGetPic
//@description: 更新UserOrderGetPic记录
//@param: userOrderGetPic *model.UserOrderGetPic
//@return: err error

func UpdateUserOrderGetPic(userOrderGetPic model.UserOrderGetPic) (err error) {
	err = global.GVA_DB.Save(&userOrderGetPic).Error
	return err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetUserOrderGetPic
//@description: 根据id获取UserOrderGetPic记录
//@param: id uint
//@return: err error, userOrderGetPic model.UserOrderGetPic

func GetUserOrderGetPic(id uint) (err error, userOrderGetPic model.UserOrderGetPic) {
	err = global.GVA_DB.Where("id = ?", id).First(&userOrderGetPic).Error
	return
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetUserOrderGetPicInfoList
//@description: 分页获取UserOrderGetPic记录
//@param: info request.UserOrderGetPicSearch
//@return: err error, list interface{}, total int64

func GetUserOrderGetPicInfoList(info request.UserOrderGetPicSearch) (err error, list interface{}, total int64) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
    // 创建db
	db := global.GVA_DB.Model(&model.UserOrderGetPic{})
    var userOrderGetPics []model.UserOrderGetPic
    // 如果有条件搜索 下方会自动创建搜索语句
    if info.OrderId != 0 {
        db = db.Where("`order_id` = ?",info.OrderId)
    }
	err = db.Count(&total).Error
	err = db.Limit(limit).Offset(offset).Find(&userOrderGetPics).Error
	return err, userOrderGetPics, total
}